package com.quktzhuanka.app.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.activity.ShopMallActivity;
import com.quktzhuanka.app.bean.ShopMallGoodsBean;
import com.quktzhuanka.app.config.Constants;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

public class ShopMallGoodsRecyclerAdapter2 extends CommonAdapter<ShopMallGoodsBean> {
    Drawable drawable;
    private OnDeleteClickLister mDeleteClickListener;
    public ShopMallGoodsRecyclerAdapter2(Context context, int layoutId, List<ShopMallGoodsBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, ShopMallGoodsBean item, int position) {
        //设置图片
        ImageView imageView = holder.getView(R.id.image);
        Glide.with(mContext).load(Constants.APP_IP+item.img).override(200,100).into(imageView);

        ((TextView)holder.getView(R.id.title_child)).setText(item.goods_name);
        holder.setText(R.id.tx2, "￥" +item.price);
        TextView tx2_2 = holder.getView(R.id.tx2_2);
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText("￥" + item.old_price);
        holder.setText(R.id.tx5, "销量:"+item.sales_volume);
        if(mContext instanceof ShopMallActivity) {
            holder.getView(R.id.tv_delete).setTag(position);
            holder.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }
    }
    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
